package com.example.mvvm.data.network

import retrofit2.await

class CoolWeatherNetwork {
    private val placeService = ServiceCreator.create(PlaceService::class.java)

    suspend fun fetchProvinceList() = placeService.getProvinces().await()

    suspend fun fetchCityList(provinceId:Int) = placeService.getCities(provinceId).await()

    suspend fun fetchCountyList(provinceId: Int, cityId: Int) =
        placeService.getCounties(provinceId, cityId).await()

    companion object {
        private var network: CoolWeatherNetwork? = null
        fun getInstance(): CoolWeatherNetwork {
            if (network == null) {
                synchronized(CoolWeatherNetwork::class.java) {
                    if (network == null) {
                        network = CoolWeatherNetwork()
                    }
                }
            }
            return network!!
        }
    }
}